$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'etcc/merchant/index',
        datatype: "json",
        colModel: [
			{ label: '用户ID', name: 'id', width: 45, key: true, sortable: false },
			{ label: '商户名称', name: 'merchant_name', width: 75 , sortable: false},
            { label: '商户联系人', name: 'merchant_linkman', width: 75 , sortable: false},
            { label: '商户联系电话', name: 'merchant_phone', width: 100, sortable: false },
            { label: '真实姓名', name: 'realName', index: "real_name",width: 100 , sortable: false},
            { label: '证件号码', name: 'identityNumber',index: "identity_number", width: 100, sortable: false },
            { label: '证件照片', name: 'identityPath', index: "identity_path",width: 100 , sortable: false, formatter: function(value, options, row){
                if (!value && typeof(value)!="undefined" && value!=0)
                {
                    return '<img src="'+value+'" style="width: 25px;height: 16px">';
                }
                return "";
            }},
			{ label: '认证类型', name: 'identityType',index: "identity_type", width: 60, sortable: false, formatter: function(value, options, row){
				return value == 1 ? '身份证' : '护照';
			}},
			{ label: '创建时间', name: 'createTime', index: "create_time", sortable: false, width: 85}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "deptId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var ztree;

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            username: null
        },
        showList: true,
        title:null,
        roleList:{},
        user:{
            status:1,
            deptId:null,
            deptName:null,
            roleIdList:[]
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        pass: function () {
            var userIds = getSelectedRows();
            if(userIds == null){
                return ;
            }
            confirm('确定要操作选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "etcc/merchant/merchantGranted",
                    contentType: "application/json",
                    data: JSON.stringify(userIds),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        getUser: function(userId){
            $.get(baseURL + "etcc/user/info/"+userId, function(r){
                vm.user = r.user;
                vm.getDept();
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'mobile': vm.q.mobile},
                page:page
            }).trigger("reloadGrid");
        }
    }
});